

//------------------------------------修改分类--------------------------------------------
    $('a[info="xiugai"]').live('click',function(){
        $('select[name="pid"]').find('option:gt(0)').remove();
        $('#lvjing').css('display','block');
        $('.tianjia').css('display','block');
        // console.log($(this).parent().prevAll().eq('2').html());
        $('input[name="id"]').remove();
        var id = $('<input type="hidden" name="id" value="'+$(this).parent().prevAll().eq('5').html()+'">');
        $('form[target="zi"]').append(id);
        $('input[name="site_name"]').val($(this).parent().prevAll().eq('4').html());
        var link = $(this).parent().prevAll().eq('3').find('a').html();
        $('input[name="site_link"]').val(link);
        $('#images').attr('src',$(this).parent().prevAll().eq('2').find('img').attr('src'));
        $('form[target="zi"]').attr('action','/admin/link/link/update')
        return false;
    });


    //-------------------------------------------------添加-------------------------------------------

    $('.add').live('click',function(){
        $('form[target="zi"]').attr('action','/admin/link/link/insert')
        $('select[name="pid1"]').find('option:gt(0)').remove();
        $('#lvjing').css('display','block');
        $('.tianjia').css('display','block');
        $('#images').attr('src','');
        $('input[name="id"]').remove();
        $('input[name="res"]').click();
        
    });

    $('a[info="del"]').live('click',function(){
        // console.log('aaa');
       var id = $(this).parent().prevAll().eq('5').html();
        $.ajax({
            url:'/admin/link/link/del',
            type:'post',
            data:{'id':id},
            success:function(mes){
                if(mes=='yes'){
                    $("#tishi").css('display','block');
                    $('#lvjing').css('display','block');
                    $("#tishi").html('<span style="color:green">删除成功,1秒后自动关闭</span>');
                    setTimeout(function(){
                        $('#lvjing').css('display','none');
                        $("#tishi").css('display','none');
                    },1000);
                    myajax();
                }else{
                    $("#tishi").css('display','block');
                    $('#lvjing').css('display','block');
                    $("#tishi").html('<span style="color:red">删除失败,1秒后自动关闭</span>');
                    setTimeout(function(){
                        $('#lvjing').css('display','none');
                        $("#tishi").css('display','none');
                    },1000);
                }
            }
        });
        return false;
    });

    function link(flag){
        if(flag=='yes'){
            $('.tianjia').css('display','none');
            myajax();
            $("#tishi").css('display','block');
            $('#lvjing').css('display','block');
            $("#tishi").html('<span style="color:green">添加成功,1秒后自动关闭</span>');
            setTimeout(function(){
                $('#lvjing').css('display','none');
                $("#tishi").css('display','none');
            },1000);
        }else{
            $('.tianjia').css('display','none');
            $("#tishi").css('display','block');
            $('#lvjing').css('display','block');
            $("#tishi").html('<span style="color:green">添加失败,1秒后自动关闭</span>');
            setTimeout(function(){
                $('#lvjing').css('display','none');
                $("#tishi").css('display','none');
            },1000);
        }
        $('input[name="res"]').click();
    }

    myajax();
    function myajax(){
        $.ajax({
            url:'/admin/link/link/data',
            type:'post',
            dataType:'json',
            success:function(mes){
                $('#con').empty();
                $(mes).each(function(i){
                    if(i%2==0){
                        var tr = $('<tr class="odd"><td class=" ">'+$(this).attr('id')+'</td><td class="sorting_1">'+$(this).attr('site_name')+'</td><td info="pname" class="hidden-480 "><a href="'+$(this).attr('site_link')+'">'+$(this).attr('site_link').split('http://')[1]+'</a></td><td class="hidden-480 "><img style="height:70px;" src="'+$(this).attr('site_pic')+'" alt="" /></td><td class="hidden-480 ">'+$(this).attr('name')+'</td><td class="hidden-480 ">'+$(this).attr('time')+'</td><td class="hidden-480 ">&nbsp;&nbsp;&nbsp;&nbsp;<a info="del" href="javascript:void(0);">删除</a>&nbsp;&nbsp;&nbsp;&nbsp;<a info="xiugai" href="">修改</a></td></tr>');
                    }else{
                        var tr = $('<tr class="odd"><td class=" ">'+$(this).attr('id')+'</td><td class="sorting_1">'+$(this).attr('site_name')+'</td><td info="pname" class="hidden-480 "><a href="'+$(this).attr('site_link')+'">'+$(this).attr('site_link').split('http://')[1]+'</a></td><td class="hidden-480 "><img style="height:70px;" src="'+$(this).attr('site_pic')+'" alt="" /></td><td class="hidden-480 ">'+$(this).attr('name')+'</td><td class="hidden-480 ">'+$(this).attr('time')+'</td><td class="hidden-480 ">&nbsp;&nbsp;&nbsp;&nbsp;<a info="del" href="javascript:void(0);">删除</a>&nbsp;&nbsp;&nbsp;&nbsp;<a info="xiugai" href="">修改</a></td></tr>');
                    }
                    $('#con').append(tr);
                });
            }
        });
    }
    function link_up(flag){
        if(flag=='yes'){
            $('.tianjia').css('display','none');
            myajax();
            $("#tishi").css('display','block');
            $('#lvjing').css('display','block');
            $("#tishi").html('<span style="color:green">修改成功,1秒后自动关闭</span>');
            setTimeout(function(){
                $('#lvjing').css('display','none');
                $("#tishi").css('display','none');
            },1000);
        }else{
            $('.tianjia').css('display','none');
            $("#tishi").css('display','block');
            $('#lvjing').css('display','block');
            $("#tishi").html('<span style="color:green">修改失败,1秒后自动关闭</span>');
            setTimeout(function(){
                $('#lvjing').css('display','none');
                $("#tishi").css('display','none');
            },1000);
        }
    }